home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir27 / calctool.zip / MATHLIB.H < prev    next >
C/C++ Source or Header  |  1992-09-09  |  8KB  |  215 lines

  1.  
  2. /*  @(#)mathlib.h 1.2 90/02/02
  3.  *
  4.  *  Definitions used with the portable math library.
  5.  *
  6.  *  This is being done because libm.a doesn't appear to be as portable
  7.  *  as originally assumed.
  8.  *
  9.  *  These routines are taken from two sources:
  10.  *
  11.  *  1/ Fred Fishs' portable maths library which was posted to the
  12.  *     comp.sources.unix newsgroup on April 1987.
  13.  *
  14.  *     acos, acosh, asin, asinh, atan, atanh, cos, cosh, dabss,
  15.  *     exp, log, log10, mod, poly, sin, sinh, sqrt, tan, tanh.
  16.  *
  17.  *  2/ The BSD4.3 maths library found on uunet in
  18.  *     bsd_sources/src/usr.lib/libm.
  19.  *
  20.  *     pow, pow_p, scalb, logb, copysign, finite, drem, exp__E,
  21.  *     log__L.
  22.  *
  23.  *  Customised and condensed by Rich Burridge,
  24.  *                              Sun Microsystems, Australia.
  25.  *
  26.  *  Permission is given to distribute these sources, as long as the
  27.  *  copyright messages are not removed, and no monies are exchanged.
  28.  *
  29.  *  No responsibility is taken for any errors or inaccuracies inherent
  30.  *  either to the comments or the code of this program, but if
  31.  *  reported to me then an attempt will be made to fix them.
  32.  */
  33.  
  34. /************************************************************************
  35.  *                                                                      *
  36.  *                              N O T I C E                             *
  37.  *                                                                      *
  38.  *                      Copyright Abandoned, 1987, Fred Fish            *
  39.  *                                                                      *
  40.  *      This previously copyrighted work has been placed into the       *
  41.  *      public domain by the author (Fred Fish) and may be freely used  *
  42.  *      for any purpose, private or commercial.  I would appreciate     *
  43.  *      it, as a courtesy, if this notice is left in all copies and     *
  44.  *      derivative works.  Thank you, and enjoy...                      *
  45.  *                                                                      *
  46.  *      The author makes no warranty of any kind with respect to this   *
  47.  *      product and explicitly disclaims any implied warranties of      *
  48.  *      merchantability or fitness for any particular purpose.          *
  49.  *                                                                      *
  50.  ************************************************************************
  51.  */
  52.  
  53. /*      This file gets included with all of the floating point math
  54.  *      library routines when they are compiled.  Note that
  55.  *      this is the proper place to put machine dependencies
  56.  *      whenever possible.
  57.  *
  58.  *      It should be pointed out that for simplicity's sake, the
  59.  *      environment parameters are defined as floating point constants,
  60.  *      rather than octal or hexadecimal initializations of allocated
  61.  *      storage areas.  This means that the range of allowed numbers
  62.  *      may not exactly match the hardware's capabilities.  For example,
  63.  *      if the maximum positive double precision floating point number
  64.  *      is EXACTLY 1.11...E100 and the constant "MAXDOUBLE is
  65.  *      defined to be 1.11E100 then the numbers between 1.11E100 and
  66.  *      1.11...E100 are considered to be undefined.  For most
  67.  *      applications, this will cause no problems.
  68.  *
  69.  *      An alternate method is to allocate a global static "double" variable,
  70.  *      say "maxdouble", and use a union declaration and initialization
  71.  *      to initialize it with the proper bits for the EXACT maximum value.
  72.  *      This was not done because the only compilers available to the
  73.  *      author did not fully support union initialization features.
  74.  */
  75.  
  76. extern double acos(), acosh(), asin(), asinh(), atan(), atanh() ;
  77. extern double cos(), cosh(), exp(), fabs(), log(), log10(), pow() ;
  78. extern double sin(), sinh(), sqrt(), tan(), tanh() ;
  79.  
  80. /*START============start of definitions from <values.h>============START
  81.  *
  82.  *  If your system has a /usr/include/values.h, or has another include
  83.  *  file which defines:
  84.  *      MAXDOUBLE       =>      Maximum double precision number
  85.  *      MINDOUBLE       =>      Minimum double precision number
  86.  *      DMAXEXP         =>      Maximum exponent of a double
  87.  *      DMINEXP         =>      Minimum exponent of a double
  88.  *
  89.  *  you can comment out these definitions down to the END line below.
  90.  */
  91.  
  92. #ifndef  BITSPERBYTE
  93. /* These values work with any binary representation of integers
  94.  * where the high-order bit contains the sign. */
  95.  
  96. /* a number used normally for size of a shift */
  97. #if gcos
  98. #define BITSPERBYTE     9
  99. #else
  100. #define BITSPERBYTE     8
  101. #endif
  102. #define BITS(type)      (BITSPERBYTE * (int)sizeof(type))
  103.  
  104. /*  Various values that describe the binary floating-point representation
  105.  *  MAXDOUBLE    - the largest double
  106.  *                       ((_EXPBASE ** DMAXEXP) * (1 - (_EXPBASE ** -DSIGNIF)))
  107.  *  MINDOUBLE    - the smallest double (_EXPBASE ** (DMINEXP - 1))
  108.  *  DMAXEXP      - the maximum exponent of a double (as returned by frexp())
  109.  *  DMINEXP      - the minimum exponent of a double (as returned by frexp())
  110.  *  DSIGNIF      - the number of significant bits in a double
  111.  *  _IEEE        - 1 if IEEE standard representation is used
  112.  *  _DEXPLEN     - the number of bits for the exponent of a double
  113.  *  _HIDDENBIT   - 1 if high-significance bit of mantissa is implicit
  114.  */
  115.  
  116. #if u3b || u3b5 || sun
  117. #define MAXDOUBLE       1.79769313486231470e+308
  118. #define MINDOUBLE       4.94065645841246544e-324
  119. #define _IEEE           1
  120. #define _DEXPLEN        11
  121. #define _HIDDENBIT      1
  122. #define DMINEXP (-(DMAXEXP + DSIGNIF - _HIDDENBIT - 3))
  123. #endif
  124.  
  125. #if pdp11 || vax
  126. #define MAXDOUBLE       1.701411834604692293e+38
  127. #define MINDOUBLE       (0.01 * 2.938735877055718770e-37)
  128. #define _IEEE           0
  129. #define _DEXPLEN        8
  130. #define _HIDDENBIT      1
  131. #define DMINEXP (-DMAXEXP)
  132. #endif
  133.  
  134. #if gcos
  135. #define MAXDOUBLE       1.7014118346046923171e+38
  136. #define MINDOUBLE       2.9387358770557187699e-39
  137. #define _IEEE           0
  138. #define _DEXPLEN        8
  139. #define _HIDDENBIT      0
  140. #define DMINEXP (-(DMAXEXP + 1))
  141. #endif
  142.  
  143. #define DSIGNIF (BITS(double) - _DEXPLEN + _HIDDENBIT - 1)
  144. #define DMAXEXP ((1 << _DEXPLEN - 1) - 1 + _IEEE)
  145.  
  146. #endif /*BITSPERBYTE*/
  147.  
  148. /*END==============end of definitions from <values.h>==================END*/
  149.  
  150.  
  151. #define  LOG2_MAXDOUBLE  (DMAXEXP + 1)
  152. #define  LOG2_MINDOUBLE  (DMINEXP - 1)
  153. #define  LOGE_MAXDOUBLE  (LOG2_MAXDOUBLE / LOG2E)
  154. #define  LOGE_MINDOUBLE  (LOG2_MINDOUBLE / LOG2E)
  155.  
  156. /*
  157.  *  The following are hacks which should be fixed when I understand all
  158.  *  the issues a little better.   |tanh(TANH_MAXARG)| = 1.0
  159.  */
  160.  
  161. #define  TANH_MAXARG     16
  162. #define  SQRT_MAXDOUBLE  1.304380e19
  163.  
  164. #define  TWOPI           (2.0 * PI)
  165. #define  HALFPI          (PI / 2.0)
  166. #define  FOURTHPI        (PI / 4.0)
  167. #define  SIXTHPI         (PI / 6.0)
  168. #define  LOG2E           1.4426950408889634074   /* Log to base 2 of e */
  169. #define  LOG10E          0.4342944819032518276
  170. #define  SQRT2           1.4142135623730950488
  171. #define  SQRT3           1.7320508075688772935
  172. #define  LN2             0.6931471805599453094
  173. #define  LNSQRT2         0.3465735902799726547
  174.  
  175. /*      MC68000 HARDWARE DEPENDENCIES
  176.  *
  177.  *      cc -DIEEE       =>      uses IEEE floating point format
  178.  *
  179.  *      Apologies for the double negative. I want as few definitions
  180.  *      needed in the default case as possible.
  181.  */
  182.  
  183. #ifndef  NOIEEE
  184. #define  X6_UNDERFLOWS   (4.209340e-52)   /* X**6 almost underflows */
  185. #define  X16_UNDERFLOWS  (5.421010e-20)   /* X**16 almost underflows */
  186. #endif /*NOIEEE*/
  187.  
  188. /*  It is hoped that your system supplies all the mathematical functions
  189.  *  required by calctool. If not then, it is possible to use the needed
  190.  *  ones from the portable math library routines that comes with these
  191.  *  sources.
  192.  *
  193.  *  There is one definition for each routine used by calctool. These are
  194.  *  commented out by default to signify that this system has that routine.
  195.  *  If you are missing any, then uncomment the appropriate definitions.
  196.  */
  197.  
  198. /*#define  NEED_ACOS  */
  199. /*#define  NEED_ACOSH */
  200. /*#define  NEED_ASIN  */
  201. /*#define  NEED_ASINH */
  202. /*#define  NEED_ATAN  */
  203. /*#define  NEED_ATANH */
  204. /*#define  NEED_COS   */
  205. /*#define  NEED_COSH  */
  206. /*#define  NEED_EXP   */
  207. /*#define  NEED_LOG   */
  208. /*#define  NEED_LOG10 */
  209. /*#define  NEED_POW   */
  210. /*#define  NEED_SIN   */
  211. /*#define  NEED_SINH  */
  212. /*#define  NEED_SQRT  */
  213. /*#define  NEED_TAN   */
  214. /*#define  NEED_TANH  */
  215.